# @Time    : 2021/6/9 16:57
# @Author  : sxh
# @Email   : 116109899@qq.com
# @File    : test1.py.py
from criterion.models import *
import pandas as pd

def run():
    hb2=Criteria.objects.get(id=3) # 河北二甲标准

    # rk_list=ReviewKey.objects.filter(clause__criteria=hb2).order_by('id')
    # print(rk_list.count())
    # for rk in rk_list:
    #     print(rk.id,rk.desc)

    file = 'db/hb2014.xls'
    df = pd.read_excel(file)  # 这个会直接默认读取到这个Excel的第一个表单
    data = df.head(5804)  # 默认读取前300行的数据
    print(data.shape[0]) # 行数
    print(data.shape[1]) # 列数
    # print(data)
    num=0
    clause = None
    for i in range(1, 5803):
        name = data.loc[i, '评审要点']
        clause_desc = data.loc[i, '评审标准']
        document = data.loc[i, '查阅资料']
        interview = data.loc[i, '访谈与追踪']
        inspect = data.loc[i, '实地查看与考核']



        clause=None
        if not pd.isnull(clause_desc):
            if not clause_desc[1]==".":
                clause_list = ReviewClause.objects.filter(criteria=hb2,desc=clause_desc)
                if clause_list.count()==1:
                    clause=ReviewClause.objects.get(criteria=hb2,desc=clause_desc)
                    # print("条款: ",clause_desc)

        if pd.isnull(name):
            pass
        elif name[0]=="【" or name[0]== "【":
            pass
        else:
            if name[1]=="." or name[1]=="、" :
                name=name[2:]
            # print(name)

            rk_list = ReviewKey.objects.filter(clause__criteria=hb2,desc=name).order_by('id')
            # rk_list = ReviewKey.objects.filter(clause=clause,desc=name).order_by('id')
            if rk_list.count()==0:
                print(0,name)
            # if rk_list.count()==1:
            #     print(1,name)
            #     # rk=ReviewKey.objects.get(clause=clause,desc=name)
            #     rk=ReviewKey.objects.get(clause__criteria=hb2,desc=name)
            #
            #     if not pd.isnull(document):
            #         if len(document)>2:
            #             if document[1] == "." or document[1] == "、":
            #                 document = document[2:]
            #             rk.document=document
            #
            #     if not pd.isnull(interview) and len(interview)>2:
            #         if interview[1] == "." or interview[1] == "、":
            #             interview = interview[2:]
            #         rk.interview=interview
            #
            #     if not pd.isnull(inspect) and len(inspect)>2:
            #         if inspect[1] == "." or inspect[1] == "、":
            #             inspect = inspect[2:]
            #         rk.inspect=inspect
            #     rk.save()
            #
            #
            # if rk_list.count()==2:
            #     print(2,name)
            #
            # if rk_list.count()>2:
            #     print(3,name)







